package dc;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class Outcome {

	private int number;
	private DCB current;
	private Proposal proposal;
	private Map<Integer, List<DCB>> bonus;
	
	private int totalMultipe;
	private int[] bonusMultipe = new int[]{0,0,0,0,0,0,0};

	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		this.number = number;
	}

	public DCB getCurrent() {
		return current;
	}

	public void setCurrent(DCB current) {
		this.current = current;
	}

	public Proposal getProposal() {
		return proposal;
	}

	public void setProposal(Proposal proposal) {
		this.proposal = proposal;
	}

	public Map<Integer, List<DCB>> getBonus() {
		return bonus;
	}

	public void setBonus(Map<Integer, List<DCB>> bonus) {
		this.bonus = bonus;
	}

	public void compute() {
		if(bonus == null){
			bonus = new TreeMap<Integer, List<DCB>>();
			if (current != null && proposal!=null && proposal.getItems() != null
					&& proposal.getItems().size() > 0) {
				for (DCB dcb : proposal.getItems()) {
					Integer aw = DCBBonus.matchAward(current, dcb);
					if (aw >= 0) {
						List<DCB> dl = bonus.get(aw);
						if (dl == null) {
							dl = new ArrayList<DCB>();
							dl.add(dcb);
							bonus.put(aw, dl);
						} else {
							dl.add(dcb);
						}
					}
				}
				
				totalMultipe = proposal.getItems().size();
				for(int i = 1 ; i <= 6; i++){
					Integer level = i;
					List<DCB> dl = bonus.get(level);
					if(dl==null){
						bonusMultipe[i] = 0;
					}else{
						bonusMultipe[i] = dl.size();
					}
				}
			}
		}
	}

	public int getTotalMultipe() {
		return totalMultipe;
	}

	public void setTotalMultipe(int totalMultipe) {
		this.totalMultipe = totalMultipe;
	}

	public int[] getBonusMultipe() {
		return bonusMultipe;
	}

	public void setBonusMultipe(int[] bonusMultipe) {
		this.bonusMultipe = bonusMultipe;
	}

	public String computeResultString() {
		compute();
		StringBuffer sb = new StringBuffer();
		sb.append("==========================================================")
				.append("\r\n");
		sb.append(number).append("期:").append("\r\n").append(current).append("\r\n");
		if (bonus.size() > 0) {
			for (Integer key : bonus.keySet()) {
				List<DCB> vv = bonus.get(key);
				sb.append(key).append("等:").append("\r\n");
				for (DCB d : vv) {
					sb.append(d).append("\r\n");
				}
			}
		}
		return sb.toString();
	}
	
	public String sumary() {
		compute();
		StringBuffer sb = new StringBuffer();
		sb.append(number).append("期 :").append("\r\n");
		if (bonus.size() > 0) {
			for (Integer key : bonus.keySet()) {
				List<DCB> vv = bonus.get(key);
				sb.append(key).append("等 :").append(vv.size()).append("\r\n");
			}
		}
		return sb.toString();
	}
}
